//
//  MessageCell.m
//  PropertyMananger
//
//  Created by Mansion on 17/3/5.
//  Copyright © 2017年 BH. All rights reserved.
//

#import "MessageCell.h"

@implementation MessageCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString * CellID = @"MessageCellID";
    MessageCell * cell = [tableView dequeueReusableCellWithIdentifier:CellID];
    if (!cell) {
        
        cell = [[MessageCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
        
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.titleLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.titleLabel];
        self.titleLabel.text = @"关于统一着装的通知。。。。";
        
        self.titleLabel.textColor = BHColor(51, 51, 51);
        self.titleLabel.font = BHFont(15);
        self.titleLabel.textAlignment = NSTextAlignmentLeft;
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self).with.offset(15);
            make.top.equalTo(self).with.offset(15);
            make.height.mas_equalTo(@25);
            
        }];
        
//        self.iconImg = [[UIImageView alloc]init];
//        [self.contentView addSubview:self.iconImg];
//        self.iconImg.image = IMG(@"ico_new");
//        
//        [self.iconImg mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.leading.equalTo(self.titleLabel.mas_trailing).with.offset(5);
//            make.centerY.equalTo(self.titleLabel).with.offset(0);
//            make.size.mas_equalTo(CGSizeMake(20, 20));
//        }];
        
        self.topButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.contentView addSubview:self.topButton];
        
        [self.topButton setImage:IMG(@"ico_top") forState:UIControlStateNormal];
        [self.topButton setTitle:@"(置顶)" forState:UIControlStateNormal];
        self.topButton.titleLabel.font = BHFont(10);
        [self.topButton setTitleColor:BHColor(102, 102, 102) forState:UIControlStateNormal];
        self.topButton.titleEdgeInsets = UIEdgeInsetsMake(0, -20, -30, 0);
        
        [self.topButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.trailing.equalTo(self).with.offset(-10);
            make.centerY.equalTo(self.titleLabel).with.offset(-5);
            make.size.mas_equalTo(CGSizeMake(30, 30));
        }];
        
        UIView * lineView = [[UIView alloc]init];
        [self.contentView addSubview:lineView];
        lineView.backgroundColor = BHColor(230, 230, 230);
        
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self).with.offset(0);
            make.bottom.equalTo(self.titleLabel.mas_bottom).with.offset(12.5);
            make.size.mas_equalTo(CGSizeMake(BHscreenW, 1));
        }];

        
        UIImageView * timeImg = [[UIImageView alloc]init];
        [self.contentView addSubview:timeImg];
        timeImg.image = IMG(@"ico_key_time");
        
        [timeImg mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.leading.equalTo(self.contentView).with.offset(15);
            make.top.equalTo(lineView.mas_bottom).with.offset(10);
            make.size.mas_equalTo(CGSizeMake(15, 15));
        }];
        
        self.timeLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.timeLabel];
        
        self.timeLabel.text = @"2017-3-4";
        self.timeLabel.textColor = BHColor(102, 102, 102);
        self.timeLabel.textAlignment = NSTextAlignmentLeft;
        self.timeLabel.font = BHFont(15);
        
        [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(timeImg.mas_trailing).with.offset(5);
            make.centerY.equalTo(timeImg).with.offset(0);
            make.size.mas_equalTo(CGSizeMake(BHscreenW/2, 25));
        }];
        
        self.contentLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.contentLabel];
        
        self.contentLabel.text = @"要求统一着装要求统一着装要求统一着装要求统一着装要求统一着装要求统一着装要求统一着装要求统一着装要求统一着装要求统一着装要求统一着装要求统一着装要求统一着装要求统一着装";
        self.contentLabel.textColor = BHColor(102, 102, 102);
        self.contentLabel.textAlignment = NSTextAlignmentLeft;
        
        self.contentLabel.font = BHFont(15);
        self.contentLabel.numberOfLines = 3;
        
        [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(timeImg.mas_trailing).with.offset(0);
            make.top.equalTo(self.timeLabel.mas_bottom).with.offset(10);
            make.size.mas_equalTo(CGSizeMake(BHscreenW - 30, 50));
        }];

        
    }
    return self;
}

- (void)setModel:(MessageModel *)model{

    _model = model;
    
    self.titleLabel.text = [NSString stringWithFormat:@"%@",model.Title];
    self.timeLabel.text = model.PublishTime;
   // self.contentLabel.text = model.NoticeContent;
    
    NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[self.model.NoticeContent dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
    self.contentLabel.attributedText = attrStr;
    self.contentLabel.textColor = BHColor(102, 102, 102);
    self.contentLabel.font = BHFont(15);
    
    NSString * top = [NSString stringWithFormat:@"%ld",model.isTop.integerValue];
   
    if ([top isEqualToString:@"1"]) {
        
        self.topButton.hidden = NO;
        
    }else{
        
    self.topButton.hidden = YES;
        
    }
    
//    NSString * read = [NSString stringWithFormat:@"%ld",model.isRead.integerValue];
    
//    if ([read isEqualToString:@"1"]) {
//        
//        self.iconImg.hidden = YES;
//        
//    }else{
//    
//    self.iconImg.hidden = NO;
//        
//    }

}

@end
